import java.util.Random;
import java.util.Scanner;

/**
 * @Author 2.0
 * @Date 2022/4/17 6:01
 * @Description  1
 */
public class TestDemo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int randNum = random.nextInt(100)+1;//随机生成[0,100)-->[1,101)
        while (true){
            System.out.println("请输入你要猜的数字：");
            int num = scanner.nextInt();
            if (num < randNum){
                System.out.println("猜小了！");
            }else if(num == randNum){
                System.out.println("猜对了！");
                break;
            }else{
                System.out.println("猜大了！");
            }
        }
    }
    //连续读取
    public static void main22(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()){
            int n = scanner.nextInt();
            System.out.println(n);
        }
    }
    public static void main21(String[] args) {
        //System.in 键盘读取数据
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();//若用scanner.next输入遇到空格读取结束  即
        System.out.println("姓名："+name);
        scanner.close();
    }
    //输出控制台
    public static void main20(String[] args) {
        System.out.println("输出且换行");
        System.out.print("输出不换行");
        System.out.printf("%d\n",90);
    }
    public static void main19(String[] args) {
        Scanner scanner =new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = 0;
        for (int j = 1; j < n; j++) {
            int ret = 1;
            for (int i = 1; i <= j; i++) {
                ret*=i;
            }
            sum +=ret;
        }
        System.out.println(sum);
    }


    //计算1！+...+5！
    public static void main18(String[] args) {
        int sum = 0;
        for (int j = 1; j < 6; j++) {
            int ret = 1;
            for (int i = 1; i <= j; i++) {
                ret*=i;
            }
            sum +=ret;
        }
        System.out.println(sum);
    }

    //同时求1~100奇数和与偶数和
    public static void main17(String[] args) {
        int sum = 0;
        int total = 0;
        for (int i = 0; i < 101; i++) {
            if(i%2!=0){
                sum+=i;
            }else {
                total+=i;
            }
        }
        System.out.println("1~100以内的奇数和为"+sum);
        System.out.println("1~100以内的偶数和为"+total);
    }
    //1~100以内的偶数和
    public static void main16(String[] args) {
        int sum = 0;
        for (int i = 0; i < 101; i+=2) {
            sum=sum+i;
        }
        System.out.println(sum);
    }
    //1~100内奇数和
    public static void main15(String[] args) {
        int sum = 0;
        for (int i = 1; i < 101; i+=2) {
            sum=sum+i;
        }
        System.out.println(sum);
    }


    public static void main14(String[] args) {
        int sum = 0;
        for (int i = 1; i < 101; i++) {
            sum=sum+i;
            continue;
        }
        System.out.println(sum);
    }
    //for循环  布尔表达是如果不写默认为真  死循环
    public static void main13(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.print(i + " ");//print(i+" ") 输出不换行
        }
    }
    //1!100内3的倍数
    public static void main12(String[] args) {
    int i = 1;
        while (i<=100) {
            if (i % 3 != 0) {
                i++;
                continue;
            }
            System.out.println(i);
            i++;
        }
    }


    //1~100第一个3的倍数
    public static void main11(String[] args) {
        int i = 1;
        while (i<=100){
            if(i%3==0){
                System.out.println(i);
                break;
            }
            i++;
        }
    }
    public static void main10(String[] args) {
        int i = 1;
        while (i<=100){
            if(i%15!=0){
                i++;
                continue;
            }
            System.out.println(i);
            i++;
        }
    }
    //既被3整除又被5整除  1~100
    public static void main9(String[] args) {
        int i =1;
        while (i<=100){
            if(i%3==0 && i%5 ==0){
                System.out.println(i);
                i++;
                continue;
            }else{

            }
            i++;
        }
    }
    //continue  如果没有上一行的i++ 则1 2 然后循环 不执行后面  跳到开头
    //break和continue必须写到循环里  swith除外
    public static void main8(String[] args) {
        int i =1;
        while (i <=10){
            if(i==3){
                i++;
                continue;
            }
            System.out.println(i);
            i++;
        }
    }
    //break
    public static void main7(String[] args) {
        int i =1;
        while (i <=10){
            if(i==3){
                break;
            }
            System.out.println(i);
            i++;
        }
    }
    //1!+2！+3！+4！+5！
    public static void main6(String[] args) {
        int j =1;
        int sum = 0;
        while (j<=5) {
            int i = 1;
            int ret = 1;
            while (i <= j) {
                ret *= i;
                i++;
            }
            sum += ret;
            j++;
        }
        System.out.println(sum);
    }

    //5！
    public static void main5(String[] args) {
        int i = 1;
        int ret = 1;
        while (i <= 5){
            ret *= i;
            i++;
        }
        System.out.println(ret);
    }


    public static void main4(String[] args) {
        int i = 1;
        int sum = 0;
        //里面的布尔表达式不能一直为true 否则死循环
        while (i <= 100) {
            sum = sum + i;
            i++;
        }
        System.out.println(sum);
    }



    public static void main3(String[] args) {
        int i = 1;
        while (i <= 10){
            System.out.println(i);
            i++;
        }
    }


    public static void main2(String[] args) {
         //java 1.5 以后  枚举 也做swith参数
        //不能做swith参数的有 long float double boolean
        String str = "1";
        switch (str){
            case "1":
                System.out.println("1");
                break;
            case "2":
                System.out.println("2");
                break;
            default:
                System.out.println("输入有误！");
                break;
        }
    }



    public static void main1(String[] args) {
        int a = 10;
        switch (a){
            case 1:
                System.out.println("1");
                break;
                //没有break会继续往下走，一般一个case对应一个break
            case 2:
                System.out.println("2");
                break;
            default:
                System.out.println("输入有误！");
                break;
        }
    }
}
